package com.stwitinc.redmine.dao.user;

import java.sql.SQLException;

import com.alibaba.fastjson.JSONObject;
import com.stwitinc.DigestAlgorithm;
import com.stwitinc.data.DbOperator;
import com.stwitinc.redmine.dao.DAO;
import com.stwitinc.redmine.dao.UserDAO;
import com.stwitinc.xmlobjects.daometadata.TokenMetaData;
import com.stwitinc.xmlobjects.daometadata.UserMetaData;

public class UserDAOImpl extends com.stwitinc.core.dao.user.UserDAOImpl implements UserDAO
{
	@Override
	public DbOperator getDbOperator() throws SQLException {
		return new DbOperator(DAO.getDataSource());
	}

	@Override
	protected String digestPassword(JSONObject user) {
		String mobilePhone = user.getString("loginId");
		String password = user.getString("password");
		return DigestAlgorithm.MD5.digestToHexString(mobilePhone + "|" + password);
	}

	@Override
	protected TokenMetaData getTokenMetaData() {
		TokenMetaData md = new TokenMetaData();
		md.setTokenTableName("web_token");
		return md;
	}

	@Override
	protected UserMetaData getUserMetaData() {
		UserMetaData md = new UserMetaData();
		md.setLoginIdColumnName("mobile_phone");
		md.setUserNameColumnName("mobile_phone");
		return md;
	}
	
	@Override
	public JSONObject getTokenById(String tokenId){
		
		
		return null;
	}

	@Override
	public int logout(String str)
	{
		// TODO Auto-generated method stub
		return 1;
	}
}
